package cn.tedu.mall.book.controller;

import cn.tedu.mall.book.pojo.dto.CategoryAddNewDTO;
import cn.tedu.mall.book.pojo.vo.CategoryListVO;
import cn.tedu.mall.book.pojo.vo.CategorySimpleVO;
import cn.tedu.mall.book.pojo.vo.CategoryTree;
import cn.tedu.mall.book.service.impl.CategoryServiceImpl;
import cn.tedu.mall.book.web.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Api(tags = "分类管理")
@RequestMapping(value = "/categories", produces = "application/json;charset=utf-8")
public class CategoryController {
    @Autowired
    CategoryServiceImpl categoryService;

    @PostMapping("/add")
    @ApiOperation("添加分类")
    // 添加分类
    public JsonResult addNew(@RequestBody CategoryAddNewDTO categoryAddNewDTO){
        categoryService.addNew(categoryAddNewDTO);
        return JsonResult.ok();
    }

    /**
     * 查询一级分类
     *
     * @return
     */
    @GetMapping("/getCategory")
    public JsonResult<List<CategorySimpleVO>> getCategory() {
        List<CategorySimpleVO> list = categoryService.getCategory();
        return JsonResult.ok(list);
    }

    /**
     * 首页分类展示
     * @return
     */
    @GetMapping("/showCategory")
    public JsonResult<List<CategoryListVO>> showCategory() {
        List<CategoryListVO> list = categoryService.showCategory();
        return JsonResult.ok(list);
    }

    @GetMapping("/get/tree")
    @ApiOperation("分类树")
    public JsonResult<List<CategoryTree>> getList(){
        return JsonResult.ok(categoryService.getTree());
    }

    /**
     * 查询与显示二级分类
     *
     * @Return 一个json结果,现在二级分类页面中展出出图书的二级分类
     */
   /* @RequestMapping("/category?id={id}")
    public JsonResult<List<CategorySimpleVO>> getChildrenCategoryByParentId(
                                            @PathVariable Integer id, Long parentId){
            List<CategorySimpleVO> list=
                     categoryService.getChildrenCategoryByParentId(parentId);
            return JsonResult.ok(list);

    }*/









}
